package com.profound.blog.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Repository;

import com.profound.blog.bean.RegUser;

@Repository
public class RegUserDAO {

	private static final String REG_USER_CLASS_NAME = RegUser.class.getName();
	@Autowired
	private SqlSessionTemplate temp;
	
	public RegUser logon(String regName,String pwd){
		RegUser u = null;
		Map map = new HashMap();
		map.put("regName", regName);
		map.put("pwd", pwd);
		u=this.temp.selectOne(REG_USER_CLASS_NAME+".logon",map);
		return u; 
	}

	public RegUser add(RegUser u){	
		String sqlID = RegUser.class.getName()+".add";
		this.temp.insert(sqlID, u);
		return u;
	}
	
	public int findByName(String regName) {
		String sqlID = RegUser.class.getName()+".findByName";
		return this.temp.selectOne(sqlID,regName);
	}
	
	public int findByEmail(String email) {
		String sqlID = RegUser.class.getName()+".findByEmail";
		return this.temp.selectOne(sqlID, email);
	}
	
	public int update(RegUser u){
		return this.temp.update(REG_USER_CLASS_NAME+".updateInfo",u);
	}
	
	public int updateSafety(RegUser u){
		return this.temp.update(REG_USER_CLASS_NAME+".updateSafety", u);
	}
}
